/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bussiness;

import DatabaseAccess.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author Nlanh_BN
 */
public class PhieuXuat {
    private String maHang;
    private String soPhieu;
    private String ngayXuat;
    private int slx;
    private String maKH;
    DBHelper conn = new DBHelper();

    public String getMaHang() {
        return maHang;
    }

    public void setMaHang(String maHang) {
        this.maHang = maHang;
    }

    public String getMaKH() {
        return maKH;
    }

    public void setMaKH(String maKH) {
        this.maKH = maKH;
    }

    public String getNgayXuat() {
        return ngayXuat;
    }

    public void setNgayXuat(String ngayXuat) {
        this.ngayXuat = ngayXuat;
    }

    public int getSlx() {
        return slx;
    }

    public void setSlx(int slx) {
        this.slx = slx;
    }

    public String getSoPhieu() {
        return soPhieu;
    }

    public void setSoPhieu(String soPhieu) {
        this.soPhieu = soPhieu;
    }

   
    public PhieuXuat(){
        
    }
    public PhieuXuat(String maHang,String soPhieu,int slx,String ngayXuat, String maKH){
        this.setMaHang(maHang);
        this.setSoPhieu(soPhieu);
        this.setNgayXuat(ngayXuat);
        this.setSlx(slx);
        this.setMaKH(maKH);
    }
    public int InsertPhieuX(PhieuXuat a) throws SQLException
    {
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMaHang());
            v.add(a.getSoPhieu());
            v.add(a.getSlx());
            v.add(a.getNgayXuat());
            v.add(a.getMaKH());
            i=conn.executeUpdate("sp_InsertPhieuX",v);
        }catch(SQLException ex){}
        return i;
    }
    public int UpdatePhieuX(PhieuXuat a) throws SQLException
    {
        DBHelper obj =new DBHelper();
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMaHang());
            v.add(a.getSoPhieu());
            v.add(a.getSlx());
            v.add(a.getNgayXuat());
            v.add(a.getMaKH());
            i=obj.executeUpdate("sp_UpdatePhieuX",v);
        }catch(SQLException ex){}
        return i;
    }
    public int DelPhieuXuat(String sophieu) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(sophieu);            
            i=conn.executeUpdate("sp_DelPhieuX",paramList);
        }
        catch(SQLException sqlex)
        {
            System.out.println(sqlex);
        }
        return i;
    }
    public Vector getAllPhieuX() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = conn.executeQuery("sp_getAllPhieuX");
            while(rs.next())
            {                  
                PhieuXuat b = new PhieuXuat();
                b.setSoPhieu(rs.getString(2));
                b.setMaHang(rs.getString(1));
                b.setSlx(rs.getInt(3));
                b.setNgayXuat(rs.getString(4)); 
                b.setMaKH(rs.getString(5));
                v.add(b);                         
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;
    }
    public Vector getPX_SoPhieu(String sophieu) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(sophieu);
        try{
            ResultSet rs = conn.executeQuery("sp_getSoPhieu", v1);
            while(rs.next()){
                PhieuXuat b = new PhieuXuat();
                b.setMaHang(rs.getString(1));
                b.setSoPhieu(rs.getString(2));
                b.setSlx(rs.getInt(3));
                b.setNgayXuat(rs.getString(4));
                b.setMaKH(rs.getString(5));

                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v; 
    }
}
